package com.zr.sms.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.deploy.ApplicationParameter;

import com.zr.sms.model.Employee;
import com.zr.sms.service.ValidateService;
import com.zr.sms.serviceimpl.ValidateServiceImpl;
/**
 * 登录功能控制层实现
 * @author wangbs
 *
 */
public class LoginServlet extends HttpServlet{
	ValidateService vs=new ValidateServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		
		String ename=req.getParameter("ename");
		String epsw=req.getParameter("epsw");
		Employee emp=vs.validateEmp(ename, epsw);
		HttpSession session =req.getSession();
		if(emp!=null){
			session.setAttribute("currentemp", emp);
			session.setMaxInactiveInterval(10000000);
			req.getRequestDispatcher("main.jsp").forward(req, resp);
		}else {
			resp.sendRedirect("login.jsp");
		}
		
	}

}
